package com.youyi.yychosesdk.ui;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.lkx.liandianqinew.R;
import com.youyi.yychosesdk.ui.adapter.PreviewPhotosFragmentAdapter;

public class PreviewFragment extends Fragment implements PreviewPhotosFragmentAdapter.OnClickListener {
    private PreviewPhotosFragmentAdapter adapter;
    private OnPreviewFragmentClickListener mListener;
    private RecyclerView rvPhotos;

    public interface OnPreviewFragmentClickListener {
        void onPreviewPhotoClick(int i);
    }

    @Override // android.support.v4.app.Fragment
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View inflate = layoutInflater.inflate(R.layout.fragment_preview_easy_photos, viewGroup, false);
        this.rvPhotos = (RecyclerView) inflate.findViewById(R.id.rv_preview_selected_photos);
        this.adapter = new PreviewPhotosFragmentAdapter(getActivity(), this);
        this.rvPhotos.setLayoutManager(new LinearLayoutManager(getActivity(), 0, false));
        this.rvPhotos.setAdapter(this.adapter);
        return inflate;
    }

    @Override // android.support.v4.app.Fragment
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnPreviewFragmentClickListener) {
            this.mListener = (OnPreviewFragmentClickListener) context;
            return;
        }
        throw new RuntimeException(context.toString() + " must implement OnPreviewFragmentClickListener");
    }

    @Override // android.support.v4.app.Fragment
    public void onDetach() {
        super.onDetach();
        this.mListener = null;
    }

    @Override // com.youyi.yychosesdk.ui.adapter.PreviewPhotosFragmentAdapter.OnClickListener
    public void onPhotoClick(int i) {
        this.mListener.onPreviewPhotoClick(i);
    }

    public void notifyDataSetChanged() {
        this.adapter.notifyDataSetChanged();
    }

    public void setSelectedPosition(int i) {
        this.adapter.setChecked(i);
        if (i != -1) {
            this.rvPhotos.smoothScrollToPosition(i);
        }
    }
}
